import 'package:flutter/material.dart';
import 'package:fluro/fluro.dart';

import './config_router.dart';
import '../public.dart';

class Routers {
  static void configureRoutes(FluroRouter router) {
    ConfigRouter(router);
  }

  // 对参数进行encode，解决参数中有特殊字符，影响fluro路由匹配(https://www.jianshu.com/p/e575787d173c)
  static Future navigateTo(
    String path, {
    Map<String, dynamic> params,
    bool clearStack = false,
    bool replace = false,
    TransitionType transition = TransitionType.inFromRight,
    BuildContext context,
  }) {
    String query = "";
    if (params != null) {
      int index = 0;
      for (var key in params.keys) {
        var value = Uri.encodeComponent(params[key].toString());
        if (index == 0) {
          query = "?";
        } else {
          query = query + "\&";
        }
        query += "$key=$value";
        index++;
      }
    }
    print('我是navigateTo传递的参数：$query');

    path = path + query;
    return ACGN.router.navigateTo(context ?? ACGN.navGK.currentContext, path,
        replace: replace, clearStack: clearStack, transition: transition);
  }
}
